home *** CD-ROM | disk | FTP | other *** search
- /* AOMUpdatePanel.c */
- /*
- * AddressOMatic Sample
- * AOMUpdatePanel.c
- * Copyright © 1993 Apple Computer Inc. All rights reserved.
- */
- #include "IconSuite.h"
- #include "AddressOMaticPrivate.h"
- #include <Palettes.h>
- #include <TextEdit.h>
-
- /*
- * These are the colors we use. They are in the Apple Icon Color 'clut'
- */
-
- const RGBColor _AOMBackgroundColor = kAOMBackgroundColor;
- const RGBColor _AOMShadowColor = kAOMShadowColor;
- const RGBColor _AOMDarkBevelColor = kAOMDarkBevelColor;
- const RGBColor _AOMLightBevelColor = kAOMLightBevelColor;
- const RGBColor _AOMWhiteColor = kAOMWhiteColor;
- const RGBColor _AOMBlackColor = kAOMBlackColor;
-
- /*
- * Redraw the panel. This is called by the user application in response to
- * an update event. The GrafPort must be set to the panel window.
- */
- pascal OSErr
- AOMUpdatePanel(
- register AddressOMaticPtr aomPtr, /* The panel */
- RgnHandle drawRgn /* What to draw */
- )
- {
- OSErr status;
- AOMSaveState saveState;
- short i;
- Rect viewRect;
-
- status = noErr;
- if (AOM.isVisible) {
- _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
- EraseRect(&INTERIOR);
- /*
- * The panel frame
- */
- PenNormal();
- viewRect = INTERIOR;
- FrameRect(&viewRect);
- if (IS_COLOR(AOM.window) && COLOR_DEPTH(AOM.window) >= 4)
- RGBForeColor(&_AOMShadowColor);
- /*
- * Draw the drop-shadow.
- */
- PenSize(kAOMDropShadowWidth, kAOMDropShadowWidth);
- MoveTo(viewRect.left + kAOMDropShadowWidth, viewRect.bottom);
- LineTo(viewRect.right, viewRect.bottom);
- LineTo(viewRect.right, viewRect.top + kAOMDropShadowWidth);
- PenNormal();
- if (IS_COLOR(AOM.window) && COLOR_DEPTH(AOM.window) >= 4) {
- InsetRect(&viewRect, 1, 1);
- RGBForeColor(&_AOMLightBevelColor);
- MoveTo(viewRect.left, viewRect.bottom - 1);
- LineTo(viewRect.left, viewRect.top);
- LineTo(viewRect.right - 1, viewRect.top);
- RGBForeColor(&_AOMDarkBevelColor);
- MoveTo(viewRect.left, viewRect.bottom - 1);
- LineTo(viewRect.right - 1, viewRect.bottom - 1);
- LineTo(viewRect.right - 1, viewRect.top);
- RGBForeColor(&_AOMBlackColor);
- RGBBackColor(&_AOMBackgroundColor);
- }
- /*
- * Update controls. Update the visible SDP panel. This could be
- * done more efficiently, especially since the update event already
- * drew the control.
- */
- if (AOM.doneButton != NULL)
- Draw1Control(AOM.doneButton);
- if (AOM.ccButton != NULL)
- Draw1Control(AOM.ccButton);
- if (AOM.toButton != NULL) {
- Draw1Control(AOM.toButton);
- _AOMDrawDefaultButtonOutline(AOM.toButton, AOM.isTarget);
- }
- /*
- * Plot the radio buttons.
- */
- for (i = 0; i < kAOMRadioButtons; i++) {
- _AOMPlotIcon(
- aomPtr, i,
- (_AOMRadioInfo[i].modeBit == AOM.currentMode)
- );
- } /* For all icons */
- switch (AOM.currentMode) {
- case kAOMEnablePDBit:
- status = _AOMPanelUpdate(aomPtr, AOM.pdPanel, drawRgn);
- break;
- case kAOMEnablePanelBit:
- status = _AOMPanelUpdate(aomPtr, AOM.browsePanel, drawRgn);
- break;
- case kAOMEnableFindBit:
- status = _AOMFindUpdate(aomPtr, drawRgn);
- break;
- #ifdef ENABLE_TYPEIN
- case kAOMEnableTypeInBit:
- status = _AOMTypeInUpdate(aomPtr, drawRgn);
- break;
- #endif
- }
- _AOMUpdateSpinner(aomPtr);
- _AOMDrawTitleString(aomPtr);
- _AOMRestoreState(&saveState);
- } /* If panel is visible */
- return (status);
- }
-
-
- void
- _AOMDrawTitleString(
- register AddressOMaticPtr aomPtr
- )
- {
- AOMSaveState saveState;
- Str255 panelTitle;
-
- _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
- panelTitle[0] = 0;
- switch (AOM.currentMode) {
- case kAOMEnablePDBit:
- GetIndString(panelTitle, AOM.stringsResID, kAOMPDTitleString);
- break;
- case kAOMEnablePanelBit:
- GetIndString(panelTitle, AOM.stringsResID, kAOMPanelTitleString);
- break;
- case kAOMEnableFindBit:
- GetIndString(panelTitle, AOM.stringsResID, kAOMFindTitleString);
- break;
- #ifdef ENABLE_TYPEIN
- case kAOMEnableTypeInBit:
- GetIndString(panelTitle, AOM.stringsResID, kAOMTypeInTitleString);
- break;
- #endif
- }
- if (panelTitle[0] > 0) {
- TextBox(
- &panelTitle[1],
- panelTitle[0],
- &TITLE,
- teJustCenter
- );
- }
- _AOMRestoreState(&saveState);
- }
-
- /*
- * Plot one of our icons. Ignore errors.
- */
- void
- _AOMPlotIcon(
- register AddressOMaticPtr aomPtr,
- short index,
- Boolean isSelected
- )
- {
- Rect viewRect;
- register AOMRadioButtonPtr buttonPtr;
- #define BUTTON (*buttonPtr)
-
- buttonPtr = (AOMRadioButtonPtr) &_AOMRadioInfo[index];
- viewRect = RADIO(index);
- viewRect.right = viewRect.left + 32;
- viewRect.bottom = viewRect.top + 32;
- (void) PlotIconID(
- &viewRect,
- (atTop | atLeft),
- (AOM.radioEnable[index]) ? ttNone : ttDisabled,
- (isSelected) ? BUTTON.selected : BUTTON.normal
- );
- }
-
- /*
- * _AOMDrawDefaultButtonOutline
- * (Adapted from Steve Falkenberg's sample)
- * Note: this function is essentially independent of the rest of
- * the AddressOMatic.
- */
- void
- _AOMDrawDefaultButtonOutline(
- ControlHandle theControl,
- Boolean doDrawButton /* FALSE erases the button */
- )
- {
- GrafPtr savePort;
- PenState savePenState;
- Rect viewRect;
- short buttonOval;
- Boolean newGray;
- RGBColor saveBackground;
- RGBColor saveForeground;
- RGBColor grayForeground;
-
- GetPort(&savePort);
- SetPort((**theControl).contrlOwner);
- GetPenState(&savePenState);
- PenNormal();
- viewRect = (**theControl).contrlRect;
- InsetRect(&viewRect, -kButtonDefaultInset, -kButtonDefaultInset);
- PenSize(kButtonDefaultPenSize, kButtonDefaultPenSize);
- buttonOval = (height(viewRect) / 2) + 2;
- if (doDrawButton == FALSE) {
- /*
- * Erase the default ring (but not the button itself).
- */
- PenMode(patBic);
- FrameRoundRect(&viewRect, buttonOval, buttonOval);
- }
- else {
- /*
- * Note that newGray will be FALSE if color is not available.
- */
- newGray = FALSE;
- if ((**theControl).contrlHilite != kActiveControl) {
- /*
- * Draw a gray outline
- */
- if (IS_COLOR((**theControl).contrlOwner)) {
- GetBackColor(&saveBackground);
- GetForeColor(&saveForeground);
- grayForeground = saveForeground;
- newGray = GetGray(
- _AOMGetDeviceFromRect(&viewRect),
- &saveBackground,
- &grayForeground
- );
- }
- if (newGray)
- RGBForeColor(&grayForeground);
- else {
- #if THINK_C
- PenPat(qd.gray);
- #else
- PenPat(&qd.gray);
- #endif
- }
- }
- FrameRoundRect(&viewRect, buttonOval, buttonOval);
- if (newGray)
- RGBForeColor(&saveForeground);
- }
- SetPenState(&savePenState);
- SetPort(savePort);
- }
-
- /*
- * This is called by functions (such as _AOMDrawDefaultButtonOutline)
- * that need to determine whether a control or window element
- * should be drawn in color.
- */
- GDHandle
- _AOMGetDeviceFromRect(
- const Rect *viewRect
- )
- {
- GDHandle device;
- Point viewCenter;
-
- SetPt(
- &viewCenter,
- viewRect->left + width(*viewRect) / 2,
- viewRect->top + height(*viewRect) / 2
- );
- LocalToGlobal(&viewCenter);
- for (device = GetDeviceList();
- device != NULL;
- device = GetNextDevice(device)) {
- if (TestDeviceAttribute(device, screenDevice)
- && TestDeviceAttribute(device, screenActive)
- && PtInRect(viewCenter, &(**device).gdRect))
- break;
- }
- if (device == NULL)
- device = GetMainDevice();
- return (device);
- }
-
-
-